﻿using Digitalmes.Domain.Entities.Mes.Processes;

namespace Digitalmes.Application.Mes.Processes.Boms.Queries;

/// <summary>
/// 分页查询 BOM 命令。
/// </summary>
/// <param name="ProductId"></param>
/// <param name="RouteId"></param>
public record GetBomWithPagedQuery(long ProductId, long RouteId) : PagedQuery, IRequest<IResult<PagedList<ProcBomDto>>>;

internal sealed class GetBomWithPagedQueryHandler(IRepository<ProcBom> repo) : IRequestHandler<GetBomWithPagedQuery, IResult<PagedList<ProcBomDto>>>
{
    public async Task<IResult<PagedList<ProcBomDto>>> Handle(GetBomWithPagedQuery request, CancellationToken cancellationToken)
    {
        var boms = await repo.GetPagedListAsync(
            m => m.ProductId == request.ProductId && m.RouteId == request.RouteId,
            request.PageNumber,
            request.PageSize,
            cancellationToken);
        return Result.From(boms.Adapt<PagedList<ProcBomDto>>());
    }
}
